"""Functionality for post-processing fields of vision"""

def fix_wall(fov, center, radius):

    for x in range(center[0], center[0] + radius):
        if (x, center[1]) not in fov:
            break
        else:
            fov.add((x, center[1] + 1))
            fov.add((x, center[1] - 1))
    for x in range(center[0], center[0] - radius, -1):
        if (x, center[1]) not in fov:
            break
        else:
            fov.add((x, center[1] + 1))
            fov.add((x, center[1] - 1))
    for y in range(center[1], center[1] + radius):
        if (center[0], y) not in fov:
            break
        else:
            fov.add((center[0] + 1, y))
            fov.add((center[0] - 1, y))
    for y in range(center[1], center[1] - radius, -1):
        if (center[0], y) not in fov:
            break
        else:
            fov.add((center[0] + 1, y))
            fov.add((center[0] - 1, y))


def circular(fov, center, radius):
    """
    circular(set of Coordinate, Coordinate, float): None
    Filters any Coordinate from the given set which fall outside the circle
    with the given radius and center. 
    """

    outside = {pos for pos in fov if _outside_circle(center, pos, radius)}
    fov.difference_update(outside)


def _outside_circle(center, pos, radius):
    a = center[0] - pos[0]
    b = center[1] - pos[1]
    return a ** 2 + b ** 2 > radius ** 2 + 1
